# -*- coding = utf-8 -*-
# @Time    : 2025/6/24 14:47
# @Author  : 杨明明
# @File    : serializers.py
# @Software: PyCharm

from rest_framework import serializers

from interfaces.models import Interface
from projects.models import Project
from test_steps.models import TestStep

class InterfaceStepSerializer(serializers.ModelSerializer):
    class Meta:
        model = TestStep
        fields = ['id', 'title']


class InterfaceSerializer(serializers.ModelSerializer):
    # project_name = serializers.CharField(label='所属项目id', help_text='接口名称', read_only=True, source='project.name')
    steps = InterfaceStepSerializer(many=True, read_only=True, source='test_steps')
    project = serializers.PrimaryKeyRelatedField(label='所属项目', help_text='所属项目',
                                           queryset=Project.objects.all().filter(is_deleted=False))

    class Meta:
        model = Interface
        exclude = ['is_deleted']  # noqa
        extra_kwargs = {    
            'name': {'required': True},
            'url': {'required': False},
            'method': {'required': True},
            'type': {'required': True},
            'project': {'required': True},
        }
